package logs
{
	import flash.external.ExternalInterface;
	import flash.utils.Dictionary;

	public class Log implements ILog
	{
		public var _errorCache:Array = new Array();
		
		public static var DEBUG:int = 1;
		public static var INFO:int = 3;
		public static var ERROR:int = 5;
		
		public static var perfix:Dictionary = new Dictionary;
		perfix[DEBUG] = "[DEBUG]";
		perfix[INFO] = "[INFO]";
		perfix[ERROR] = "[ERROR]";
		
		public function log(level:int, content:String):void {
			var p:String = perfix[level];
			if (p == null) return;
			trace(p+content);
		}
		
		public function debug(...args):void {
			log(DEBUG, args.join(" "));
		}
		
		public function info(...args):void {
			log(INFO, args.join(" "));
		}
		
		public function error(...args):void {
			var errStr:String = args.join(" ");
			_errorCache.push(errStr);
			var bt:String = (new Error).getStackTrace();
			log(ERROR, errStr + "\n" + bt);
			alert(errStr + "\n" + bt);
		}
		
		public function alert(v:String):void
		{
//			trace("[ALERT]", v);
			if (ExternalInterface.available)
			{
				ExternalInterface.call("alert", v);
			}	
		}
		
		public function flush():String {
			return "";
		}
	}
}